<?php
namespace view;

class CommentView {
    private $m_commentText;
    private $m_commentStatusMessage ="";
    private $commentModel;


    /**
    * @param object \controller\CommentController $commentModel
    */
    public function __construct(\model\CommentModel $commentModel)     {
        $this->commentModel = $commentModel;
    }


    /**
    * @return boolean
    */
    public function wantsToCommentBlogPost() {
        if (isset($_GET[$this->commentModel->applicationModel->m_addCommentURL]) ) {
                return true;
        } else {
                return false;
        }
    }


    /**
    * @return boolean
    */
    public function hasNewCommentInput() {
        if (isset($_POST[$this->commentModel->applicationModel->m_postCommentText]) ) {
            return true;
        } else {
            return false;
        }
    }


    /**
    * @param string
    */
    public function returnNewCommentInput() {
        return $this->m_commentText;
    }


    /**
    * @return boolean
    */
    public function wantsToShowComments() {
        if (isset($_GET[$this->commentModel->applicationModel->m_showBlogCommentsURL]) ) {
                return true;
        } else {
                return false;
        }
    }


    /**
    * @param string $commentText
    */
    public function setNewCommentInput($commentText) {
        $this->m_commentText = $commentText;
    }


    /**
    * @return string
    */
    public function getNewCommentInput() {
            $commentText = $_POST[$this->commentModel->applicationModel->m_postCommentText];
            return $commentText;
    }


    /**
    * @return boolean
    */
    public function wantsToEditComment() {
        if (isset($_GET[$this->commentModel->applicationModel->m_editCommentURL]) ) {
                return true;
        } else {
                return false;
        }
    }


    /**
    * @return boolean
    */
    public function hasUpdatedCommentInput() {
        if (isset($_POST[$this->commentModel->applicationModel->m_postUpdatedCommentText]) ) {
            return true;
        } else {
            return false;
        }
    }


    /**
    * @param string
    */
    public function getUpdatedCommentInput() {
        $commentText = $_POST[$this->commentModel->applicationModel->m_postUpdatedCommentText];
        return $commentText;
    }


    /**
    *
    */
    public function setUpdatedCommentInput($commentText) {
        $this->m_updatedCommentText = $commentText;
    }


    /**
    * @return string
    */
    public function returnUpdatedCommentInput() {
        return $this->m_updatedCommentText;
    }


    /**
    * @return string $id
    */
    public function returnCommentId() {
        if (isset($_GET[$this->commentModel->applicationModel->m_showBlogCommentsURL])){
               $id = $_GET[$this->commentModel->applicationModel->m_showBlogCommentsURL];
               return $id;

        } else if (isset($_GET[$this->commentModel->applicationModel->m_addCommentURL])){
               $id = $_GET[$this->commentModel->applicationModel->m_addCommentURL];
               return $id;

        }  else if (isset($_GET[$this->commentModel->applicationModel->m_editCommentURL])){
               $id = $_GET[$this->commentModel->applicationModel->m_editCommentURL];
               return $id;

        } else if(isset($_GET[$this->commentModel->applicationModel->m_deleteCommentURL])) {
               $id = $_GET[$this->commentModel->applicationModel->m_deleteCommentURL];
               return $id;
        }
    }


    /**
    * @param string $type
    * @param string $statusCode
    * @return boolean
    */
    public function setCommentStatusMessage($type, $statusCode) {
        if($statusCode==1) {
       		$statusMessage ="Your comment must have at least "
       		. $this->commentModel->applicationModel->m_minNumberCommentText . "characters!" ;

        } else if ($statusCode==2) {
            if ($type == $this->commentModel->applicationModel->m_newType) {
                $commentText = $this->getCommentInput();
            } else if($type == $this->commentModel->applicationModel->m_updateType) {
                $commentText = $this->getupdatedCommentInput();
            }
       			$statusMessage =  "Your comment can only have ".$this->commentModel->applicationModel->m_maxNumberCommentText
       			." characters!<br>Number of characters in post are ". (strlen($commentText));

        } else if ($statusCode==3) {
            $statusMessage =  "Your post contains invalid characters! <br>Invalid characters have been removed." ;
        }  else {
             $statusMessage =  "";
        }

        $this->m_commentStatusMessage .= $statusMessage;
    }


    /**
    * @return string
    */
    public function returnCommentStatusMessage() {
        return $this->m_commentStatusMessage;
    }


    /**
    * @return boolean
    */
    public function wantsToRemoveComment() {
        if (isset($_GET[$this->commentModel->applicationModel->m_deleteCommentURL]) ) {
                return true;
        } else {
                return false;
        }
    }


}

